package DictionaryTest;

import Practice.AddButton;
import Practice.AddText;
import Practice.JFrameTest;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileReader;
import java.util.Properties;

public class DictionaryJFrame extends JFrame {
    private AddText english = new AddText("请输入",50,30,this);
    private JLabel jl = new JLabel();
    private Properties p = new Properties();



    public DictionaryJFrame(){
        this.setLayout(null);
        AddButton a = new AddButton("查询",400,30,this);
        jl.setBounds(200,200,200,100);
        this.add(jl);

        a.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                search();
            }
        });



        this.setSize(500,600);
        this.setVisible(true);
        this.setDefaultCloseOperation(3);
        this.setLocationRelativeTo(null);
    }

    private void search(){
        try {
            p.load(new FileReader("Class9_6/src/Dictionary.txt"));
        }catch (Exception e){
            System.out.println("文件不存在");
        }

        String value = p.getProperty(english.getText());
        if (value == null){
            this.jl.setText("没有找到");
        }else {
            this.jl.setText(value);
        }
    }


    public static void main(String[] args) {
        new DictionaryJFrame();
    }
}
